module view {
    //建造	
    export class DevelopView extends eui.Component {
        closeBtn: eui.Button
        developGroup: eui.Group
        public constructor() {
            super()
            this.addEventListener(eui.UIEvent.COMPLETE,this.onComplete,this)
            this.skinName = "resource/skin/DevelopmentSkin.exml"
        }

        private onComplete(): void {
            this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.close,this)
            for(var i in templateConfig.development) {
                console.log(i)
                var developBlock = new DevelopBlock(i, this)
                this.developGroup.addChild(developBlock)
            }
        }

        private close(): void {
            this.parent.removeChild(this)
        }
         
        
    }

    class DevelopBlock extends eui.Component {
        nameLabel: eui.Label
        nameBtn: eui.Button
        btn: eui.Button
        desLabel: eui.Label
        developId: number
        explainBtn: eui.Button
        developView: DevelopView
        explainView: ExplainView
        public constructor(developId,developView: DevelopView) {
            super()
            this.skinName = "resource/skin/DevelopBlockSkin.exml"
            this.developId = developId
            this.developView = developView
            this.btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.build,this)
            this.nameBtn.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.explain,this)
            this.explainBtn.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.explain,this)
            this.nameBtn.addEventListener(egret.TouchEvent.TOUCH_END,this.explainClose,this)
            this.explainBtn.addEventListener(egret.TouchEvent.TOUCH_END,this.explainClose,this)
            this.nameBtn.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.explainClose,this)
            this.explainBtn.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.explainClose,this)
            this.showBuildInfo()
        }
        
        private explain(evt:egret.TouchEvent){
            var buildConfig = totalConfig[this.developId].lvl[0]
            this.explainView = new ExplainView(totalConfig[this.developId])
            this.developView.addChild(this.explainView)
            this.explainView.show()
        }
        
        private explainClose(evt: egret.TouchEvent) { 
            this.developView.removeChild(this.explainView)
        }
        
        private showBuildInfo(){
            var buildConfig = totalConfig[this.developId].lvl[0]
            var txt = ''
            for(var i in buildConfig.items) {
                var item = buildConfig.items[i]
                var itemName = templateName[item[0]]
                var num = item[1]
                txt += itemName + 'X' + num
            }
            this.nameLabel.text = totalConfig[this.developId].name
            this.desLabel.text = txt           
        }

        private build(){
            var buildConfig = totalConfig[this.developId].lvl[0]
            var ret = game.utilsHandle.removeItemsAndGold(gplayer, buildConfig)
            if(ret === -1) {
                return
            }
            var nowTime = new Date().getTime()
            this.showBuildInfo()
        }
    }
    
    class ExplainView extends eui.Component{
        nameLabel : eui.Label
        contentLabel : eui.Label
        info :any
        public constructor(info){
            super()
            this.skinName = "resource/skin/ExplainSkin.exml"
            this.info = info
        }
        
        public show(){
            this.horizontalCenter = 0
            this.y = this.stage.height / 2
            this.nameLabel.text = this.info.name
            this.contentLabel.text = '介绍说明'
        }
    }
}
